package com.example.pattern.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 *
 * @author FM_南风
 * @date 2024/6/27
 */
public class FlyweightFactory {

    private static final Map<String, FlyweightInterface> flyweightMap = new HashMap<>();

    public static FlyweightInterface getCircle(String color) {
        FlyweightClass flyweightClass = (FlyweightClass) flyweightMap.get(color);

        if (flyweightClass == null) {
            flyweightClass = new FlyweightClass(color);
            flyweightMap.put(color, flyweightClass);
            System.out.println("开始创作: " + color);
        }
        return flyweightClass;
    }
}
